#include <stdio.h>

typedef struct {
	char name[20];  
	int age;        
} Student;

int main() {
	Student p;
	FILE *file;
	

	file = fopen("student.dat", "w");  
	if (file == NULL) {
		printf("文件打开失败！");
		return 1;
	}
	
	printf("请输入姓名：");
	scanf("%s", p.name);
	printf("请输入年龄：");
	scanf("%d", &p.age);
	
	fwrite(&p, sizeof(Student), 1, file);  
	fclose(file);
	printf("数据已保存到文件！");
	
	
	file = fopen("student.dat", "r");  
	if (file == NULL) {
		printf("文件读取失败！");
		return 1;
	}
	
	fread(&p, sizeof(Student), 1, file);  
	fclose(file);
	
	printf("\n读取到的信息：");
	printf("姓名：%s，年龄：%d", p.name, p.age);
	
	return 0;
}
